package com.softeem.music_sys.controller;

import com.softeem.music_sys.comm.QiniuOssUtils;
import com.softeem.music_sys.comm.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @version 1.0
 * @Author cn
 * @Date 2025/11/11 09:54
 * @Description
 */
@Tag(name = "文件上传", description = "文件上传下载")
@RestController
public class FileController {
    @Operation(summary = "上传文件",description = "文件上传接口")
    @PostMapping("file/upload")
    public Result upload(MultipartFile file) throws  Exception{
        InputStream in = file.getInputStream();
        String filename = file.getOriginalFilename();

//        System.out.println(file.getSize());
//        System.out.println(file.getContentType());
//
//        File myfile = new File("D:\\music_sys_file", filename);
//        OutputStream out = new FileOutputStream(myfile);
//      in.transferTo(out);
        QiniuOssUtils Utils = new QiniuOssUtils();
        String url = Utils.upload(in, filename);
        return Result.success().setMessage("上传成功").setData(url);
    }
}
